/**
 * ProjectLayersDao.java
 *
 * Copyright (c) 2010 Prj.Manager All Rights Reserved.
 *
 * This source file may not be copied, modified or redistributed,
 * in whole or in part, in any form or for any reason, without the express
 * written consent of Prj.Manager .
 **/

package ro.prjmanager.dao;

import org.hibernate.Query;
import ro.prjmanager.core.dao.GenericDAO;
import ro.prjmanager.core.list.ListSqlParser;
import ro.prjmanager.core.list.SQL;
import ro.prjmanager.model.ProjectLayers;
import ro.prjmanager.model.Projects;

import java.util.List;

/**
 * This interface provides custom method declaration for ProjectLayers
 * entity and has a default implementation in the same package :
 * ProjectLayersDAOImpl
 * @author Viorel Tacliciu
 * @version 2
 */

@SuppressWarnings({"unchecked"})
public class ProjectLayersDao extends GenericDAO<ProjectLayers,  java.lang.Integer> {
    
    @Override
    public List<ProjectLayers> listPagFilter(int startPage, int resPerPage, String sqlFilter) {
        StringBuilder sql=new StringBuilder("select c from  ").append(getPersistentClass().getName()).append(" as c ");
         SQL sqlFilterParsed= ListSqlParser.parseSqlListParameter(sqlFilter);
          sql.append(" ").append(sqlFilterParsed.getBeforeWhereParent()) ;
         sql.append(" where c.fkProject.id=")
                .append(((Projects)getUserSession().getProject()).getId());
          sql.append(" ").append(sqlFilterParsed.getAfterWhereParent()) ;
        Query sqlQuery=getSession().createQuery(sql.toString());
        sqlQuery.setMaxResults(resPerPage);
        sqlQuery.setFirstResult(startPage);

        return sqlQuery.list();
    }

    @Override
    public List<ProjectLayers> findAll() {
        StringBuilder sb=new StringBuilder("select c from ");
        sb.append(getPersistentClass().getName()).append(" as c where c.fkProject.id=");
        sb.append(((Projects)getUserSession().getProject()).getId());
        return getSession().createQuery(sb.toString()).list();
    }
}
